//
//  HomeApi.swift
//  MT
//
//  Created by M on 2019/12/17.
//  Copyright © 2019 张强. All rights reserved.
//

import Foundation

/// 网络
import Moya
import DeviceKit
import SwiftyRSA
import Security

import Result

enum HomeApi {
    
    /// 单页页数
    static var defaultPageSize: Int = 10
    /// 热门列表
    case hotList(curPage: Int, sex: Int)
    /// 热门列表（性别 = unknown）
    case hotListWithoutGender(curPage: Int)
    /// 最新列表
    case latestList(curPage: Int, sex: Int)
    /// 最新列表（性别 = unknown）
    case latestListWithoutGender(curPage: Int)
    /// 屏蔽用户
    case moment(blackUserId: Int)
    /// 点赞
    case trendsLike(userName: String)
    /// 动态i点赞
    case realTrendsLike(trendId: Int)
    
}

// MARK: ------------------ Api 参数 ----------------------
extension HomeApi: MTTargetType {

    /// 请求头
    public var headers: [String : String]? {
        guard let accessToken = UserDefaults.MTUserCenter.token.storedString else { return nil }
        return ["Access-Token": accessToken]
    }
    
    /// 基路径
    public var baseURL: URL {
        return URL(string: AuthServerBaseUrl)!
    }
    
    /// 路径
    public var path: String {
        switch self {
            /// 热门列表
        case .hotList, .hotListWithoutGender:
            return "/user/hots"
            
            /// 最新列表
        case .latestList, .latestListWithoutGender:
            return "/user/latest"
        case .moment:
            return "/user/black"
        case .trendsLike:
            return "/user-cent/like"
        case .realTrendsLike:
            return "/trends/like"
            
        }
    }
    
    /// 请求方法
    public var method: Moya.Method {
        switch self {
        default:        return .post
        }
    }
    
    /// 参数
    var params: [String: Any]? {
        
        switch self {
            /// 热门列表
        case let .hotList(curPage, sex):
            return ["pageSize": HomeApi.defaultPageSize, "curPage": curPage, "sex": sex]
            
            /// 热门列表（性别 = unknown）
        case let .hotListWithoutGender(curPage):
            return ["pageSize": HomeApi.defaultPageSize, "curPage": curPage]
            
            /// 最新列表
        case let .latestList(curPage, sex):
            return ["pageSize": HomeApi.defaultPageSize, "curPage": curPage, "sex": sex]
            
            /// 最新列表（性别 = unknown）
        case let .latestListWithoutGender(curPage):
            return ["pageSize": HomeApi.defaultPageSize, "curPage": curPage]
        
        case let .moment(blackUserId):
            return ["blackUserId" : blackUserId]
            
        case let .trendsLike(userName):
            return ["userName" : userName]
        case let .realTrendsLike(trendId):
            return ["trendId" : trendId]
        }
        
    }
    
}
